{{extend './layout.htm'}}

{{block 'main'}}
<div class="table-wrap">
    <table class="layui-table">
        <thead>
            <tr><th>ID</th><th>分类</th><th>地址</th><th>排序</th><th>显示</th><th>编辑</th></tr> 
        </thead>
        <tbody>
            {{each list item}}
            <tr>
                <td>{{item.id}}</td>
                <td>{{item.cate_name}}</td>
                <td>{{item.cate_dir}}</td>
                <td>{{item.sort}}</td>
                <td>{{item.is_show ? '显示' : '隐藏'}}</td>
                <td><a href="{{url('form', {id: item.id})}}" class="layui-btn layui-btn-sm">编辑</a><a href="{{url('delete', {id: item.id})}}" class="layui-btn layui-btn-danger layui-btn-sm">删除</a></td>
            </tr>{{/each}}
        </tbody>
    </table>
</div>
<div style="text-align: center;">
    <a href="{{url('form')}}" class="layui-btn">新增分类</a>
</div>
{{/block}}

{{block 'js'}}
<script>
    layui.use(['form', 'layer'], function(){
        var form = layui.form;
        var layer = layui.layer;

        $('a.layui-btn-danger').each(function(){
            var url = $(this).attr('href');
            $(this).attr('href', 'javascript:;').click(function () {
                layer.confirm("确定删除吗？", function(index){
                    layer.close(index);
                    $.get(url, function(re){
                        if(re.state){
                            layer.msg(re.msg, function(){
                                history.go(0);
                            });
                        }else{
                            layer.msg(re.msg);
                        }
                    });
                });
            });
        });
    });
</script>
{{/block}}